<template>
    <div class="home">
        <div class="side">
            <p class="title">选课系统</p>
            <el-menu
                    default-active="2"
                    class="el-menu"
                    @open="handleOpen"
                    @close="handleClose"
                    background-color="#222222"
                    text-color="#fff"
                    active-text-color="#ffd04b">
                <template v-for="(item,i) in menus">

                    <el-submenu v-if="item.children && item.children.length!=0" :index="i.toString()">
                        <template slot="title">
                            <i class="el-icon-location"></i>
                            <span>{{ item.title }}</span>
                        </template>
                        <el-menu-item
                                v-for="(m,idx) in item.children"
                                :index="i+'-'+idx"
                                @click="handleGo(m)"
                        >{{ m.title }}</el-menu-item>
                    </el-submenu>

                    <el-menu-item
                            v-else
                            :index="i.toString()"
                            @click="handleGo(item)"
                    >
                        <i class="el-icon-menu"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>

                </template>

            </el-menu>
        </div>
        <div class="main">
            <div class="header"></div>
            <div class="container">
                <router-view/>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Home",
        methods: {
            handleOpen(key, keyPath) {
                console.log(key, keyPath);
            },
            handleClose(key, keyPath) {
                console.log(key, keyPath);
            },
            handleGo(item) {
                this.$router.push({name: item.name})
            }
        },
        computed: {
            menus() {
                return this.$store.state.permission
            }
        }
    }
</script>

<style scoped>
    .home {
        display: flex;
    }
    .side {
        position: absolute;
        left: 0;
        top: 0;
        width: 220px;
        bottom: 0;
        background: #222222;
        overflow: auto;
    }
    .side .title {
        line-height: 50px;
        text-align: center;
        color: rgba(255,255,255,0.8);
    }
    .el-menu {
        width: 100%;
    }
    .main {
        flex: 1;
        position: absolute;
        left: 220px;
        top: 0;
        right: 0;
        bottom: 0;
    }
    .main .header {
        position: fixed;
        left: 220px;
        top: 0;
        right: 0;
        height: 50px;
        background: white;
        box-sizing: border-box;
    }
    .main .container {
        position: absolute;
        left: 0;
        top: 50px;
        right: 0;
        bottom: 0;
        padding: 15px;
        box-sizing: border-box;
        background: #f2f2f2;
        overflow: auto;
    }

</style>